
/*-----加载模板-------*/
$(document).ready(function(){
    $(".sidebar_list").click(function(){
        $('li').removeClass("active");
        $(this).parent("li").addClass("active");
        var url=$(this).attr("href");
        $.post(url,'',function(data){
            $(".span9").html(data);

            //课程基本信息当前页面修改功能
            $('.info_change').click(function(e) {
                var data = {};
                data['id']=$(this).attr('title');
                $(this).parent().parent().siblings().children('td').children('input').attr('readonly','readonly');
                $(this).parent().siblings().children('input').removeAttr('readonly');
                $(this).parent().siblings().children('input').blur(function(){
                    $(this).parent().parent().children('td').children('input').each(function(e) {
                        data[this.name] = this.value;
                    });
                    var base=$('#base').val();
                    $.post(base+"admin/course/course_base_update",data);
                })
                e.preventDefault();
                return false;
            });
        })
        return false;
    });
});
/*------------选择学院------------------*/
function change_select(){
    $('#academy').change(function(){
        var id=$("#academy").val();
        var base=$("#base").val();
        if(id==''){
            $("#major").attr("disabled","disabled").html("<option value=''>请选择</option>");
        }else{
            $("#major").removeAttr("disabled");
            $.post(base+"admin/infoManage/getMajor",{id:id},change_call_back,"json");
        }
    });
};
function change_call_back(rs){
    if(rs.success){
        var str = "<option value=''>请选择</option>";
        for(var i in rs.data)
        {
            str += ("<option value='" + rs.data[i].number + "'>" + rs.data[i].name + "</option>");
        }
        $("#major").html(str);
    }else{
        var str="<option value=''>请选择</option>"+"<option value=''>无</option>";
        $("#major").html(str);
    }
}

/*------------表单添加提交功能---------*/
function add_form(){
    var url=$("#add_form").attr("action");
    var data=$("#add_form").serialize();
    $.post(url,data,add_back,'json');
    return false;
}
function add_back(rs){
    alert(rs.msg);
}
/*---------表单提交后返回模板功能--------*/
function back_plane(){
    var url=$("#back_form_plane").attr("action");
    var data=$("#back_form_plane").serialize();
    $.post(url,data,function(rs){
        if(rs.success){
            $("#search_result").html(rs.panel);
        }else{
            alert(rs.msg);
        }
    },"json");
    return false;
};
/*-----分页----------*/
function pageInfo(point){
    var url=$(point).attr("href");
    var data=$("#back_form_plane").serialize();
    $.post(url,data,function(rs){
        if(rs.success){
            $("#search_result").html(rs.plane);
        }else{
            alert(rs.msg);
        }
    },"json");
    return false;
}
/*------信息修改返回模板------*/
function info_change(point){
    var url=$(point).attr("href");
    var title=$(point).attr("title");
    if(title){
        $.post(url,{title:title},function(data){
            $(".span9").html(data);
        });
    }else{
        $.post(url,'',function(data){
            $(".span9").html(data);
        });
    }
    return false;
}
/*-------------删除信息-----------*/
function delete_course(e){
    var base=$('#base').val();
    var url=$(e).attr("href");
    $.post(url,'',function(data){
        alert(data.msg);
        $.post(base+"admin/course/course_list_panel",'',function(rs){

        },'json')
    },'json');
    return false;
};
/*--------------课程安排，课程选择--------------*/
function change_course(){
    $('#name').change(function(){
        var id=$("#name").val();
        var base=$("#base").val();
        if(id==''){
            $("#teacher").html("<option value=''></option>");
        }else{
            $.post(base+"admin/course/getTeacher",{id:id},change_course_back,"json");
        }
    });
};
function change_course_back(rs){
    if(rs.success){
        var str = "<option value=''></option>";
        for(var i in rs.data)
        {
            str += ("<option value='" + rs.data[i].t_id + "'>" + rs.data[i].name + "</option>");
        }
        $("#teacher").html(str);
    }else{
        var str="<option value=''></option>";
        $("#teacher").html(str);
    }
}
/*------选课--------*/
function course_select(rs){
    var base=$('#base').val();
    var url=$(rs).attr('href');
    var title=$(rs).attr('title');
    $.post(url,title,function(data){
        alert(data.msg);
    },'json');
    $.post(base+"admin/student/course_select_panel",'',function(data){
        $(".span9").html(data);
    });
    return false;
}
//课程基本信息当前页面修改功能
function current_page_change(e){
    var data = {};
    data['semester']=$(e).attr('title');
    var url=$(e).attr('href');
    $(e).parent().parent().siblings().children('td').children('input').attr('readonly','readonly');
    $(e).parent().siblings().children('input[name="grade"]').removeAttr('readonly');
    $(e).parent().siblings().children('input').blur(function(){
        data['grade']=$(e).parent().siblings().children('input[name="grade"]').val();
        $.post(url,data,function(rs){
            if(rs.success=='false'){
                alert(rs.msg);
            }
        },'json');
    });
    return false;
}
/*-------------------教师选择选修课---------------*/
function teacher_elective_update(e){
    var url=$(e).attr('href');
    var u=$('#current_page').attr('href');
    var data=$("#back_form_plane").serialize();
    $.post(url,'',function(rs){
        if(rs.success){
            alert(rs.msg);
            $.post(u,data,function(rs){
                if(rs.success){
                    $("#search_result").html(rs.panel);
                }else{
                    alert(rs.msg);
                }
            },"json");
        }else{
            alert(rs.msg);
        }
    },'json');
    return false;
};